package com.fgchen.study.user.server;

import com.fgchen.study.user.service.LoginService;
import com.fgchen.study.user.service.UserService;
import com.fgchen.study.user.service.impl.LoginServiceImpl;
import com.fgchen.study.user.service.impl.UserServiceImpl;
import org.apache.thrift.TMultiplexedProcessor;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadedSelectorServer;
import org.apache.thrift.transport.TNonblockingServerSocket;

/**
 * Created by fgchen on 2017/7/17.
 */
public class MyServer {

    public static void main(String[] args) throws Exception {
        TNonblockingServerSocket transport = new TNonblockingServerSocket(8888);

        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor("UserService", new UserService.Processor<>(new UserServiceImpl()));
        processor.registerProcessor("LoginService", new LoginService.Processor<>(new LoginServiceImpl()));

        TServer server = new TThreadedSelectorServer(
                new TThreadedSelectorServer.Args(transport)
                        .processor(processor)
                        .protocolFactory(new TJSONProtocol.Factory())
                        .workerThreads(6)
                        .selectorThreads(2)
        );
        server.serve();
    }

}
